package cn.livingCloud.dto;

import cn.livingCloud.entity.core.CaseRecord;
import cn.livingCloud.entity.core.CaseRecordType;
import cn.livingCloud.entity.core.Employee;
import cn.livingCloud.utils.DateUtils;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 唐旭 on 2016/6/3.
 */
public class CaseRecordDto {
    private String uuid;
    private String createDateTime;
    private String caseUuid;
    private String operatorUuid;
    private EmployeeDto operatorDto;
    private Boolean archive = false;
    private CaseRecordType type;
    private String oldOwnerId;
    private List<EmployeeDto> oldOwnerList = new ArrayList<>();
    private String newOwnerId;
    private List<EmployeeDto> newOwnerList = new ArrayList<>();
    private String content;
    private String userUuid;
    private UserDto userDto;

    public CaseRecordDto() {
    }

    public CaseRecordDto(CaseRecord record) {
        this.uuid = record.getUuid();
        this.createDateTime = DateUtils.toDateText(record.getCreateDateTime()
                , DateUtils.DEFAULT_DATE_TIME_FORMAT);
        this.caseUuid = record.getCaseUuid();
        this.operatorUuid = record.getOperator();
        if (StringUtils.isNotEmpty(operatorUuid)) {
            this.operatorDto = new EmployeeDto(record.getOperatorEmployee());
        }
        this.archive = record.getArchive();
        this.type = record.getType();
        this.oldOwnerId = record.getOldOwnerId();
        if (StringUtils.isNotEmpty(oldOwnerId)) {
            List<Employee> owners = record.getOldOwnerList();
            for (Employee owner : owners) {
                this.oldOwnerList.add(new EmployeeDto(owner));
            }
        }
        this.newOwnerId = record.getNewOwnerId();
        if (StringUtils.isNotEmpty(newOwnerId)) {
            List<Employee> owners = record.getNewOwnerList();
            for (Employee owner : owners) {
                this.newOwnerList.add(new EmployeeDto(owner));
            }
        }
        this.content = record.getContent();
        this.userUuid = record.getOperatorUserUuid();
        if (StringUtils.isNotEmpty(userUuid)) {
            this.userDto = new UserDto(record.getOperatorUser());
        }
    }

    public Boolean getArchive() {
        return archive;
    }

    public CaseRecordDto setArchive(Boolean archive) {
        this.archive = archive;
        return this;
    }

    public String getCaseUuid() {
        return caseUuid;
    }

    public CaseRecordDto setCaseUuid(String caseUuid) {
        this.caseUuid = caseUuid;
        return this;
    }

    public String getContent() {
        return content;
    }

    public CaseRecordDto setContent(String content) {
        this.content = content;
        return this;
    }

    public String getCreateDateTime() {
        return createDateTime;
    }

    public CaseRecordDto setCreateDateTime(String createDateTime) {
        this.createDateTime = createDateTime;
        return this;
    }

    public List<EmployeeDto> getNewOwnerList() {
        return newOwnerList;
    }

    public CaseRecordDto setNewOwnerList(List<EmployeeDto> newOwnerList) {
        this.newOwnerList = newOwnerList;
        return this;
    }

    public String getNewOwnerId() {
        return newOwnerId;
    }

    public CaseRecordDto setNewOwnerId(String newOwnerId) {
        this.newOwnerId = newOwnerId;
        return this;
    }

    public List<EmployeeDto> getOldOwnerList() {
        return oldOwnerList;
    }

    public CaseRecordDto setOldOwnerList(List<EmployeeDto> oldOwnerList) {
        this.oldOwnerList = oldOwnerList;
        return this;
    }

    public String getOldOwnerId() {
        return oldOwnerId;
    }

    public CaseRecordDto setOldOwnerId(String oldOwnerId) {
        this.oldOwnerId = oldOwnerId;
        return this;
    }

    public EmployeeDto getOperatorDto() {
        return operatorDto;
    }

    public CaseRecordDto setOperatorDto(EmployeeDto operatorDto) {
        this.operatorDto = operatorDto;
        return this;
    }

    public String getOperatorUuid() {
        return operatorUuid;
    }

    public CaseRecordDto setOperatorUuid(String operatorUuid) {
        this.operatorUuid = operatorUuid;
        return this;
    }

    public CaseRecordType getType() {
        return type;
    }

    public CaseRecordDto setType(CaseRecordType type) {
        this.type = type;
        return this;
    }

    public String getUuid() {
        return uuid;
    }

    public CaseRecordDto setUuid(String uuid) {
        this.uuid = uuid;
        return this;
    }

    public UserDto getUserDto() {
        return userDto;
    }

    public CaseRecordDto setUserDto(UserDto userDto) {
        this.userDto = userDto;
        return this;
    }

    public String getUserUuid() {
        return userUuid;
    }

    public CaseRecordDto setUserUuid(String userUuid) {
        this.userUuid = userUuid;
        return this;
    }

    public String getName() {
        if (userDto != null) {
            return userDto.getName();
        } else if (operatorDto != null) {
            return operatorDto.getName();
        } else {
            return "无";
        }
    }
}
